{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Python 编程思想\n",
    "通过import this我们可以看到python的编程思想。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Zen of Python, by Tim Peters\n",
      "\n",
      "Beautiful is better than ugly.\n",
      "Explicit is better than implicit.\n",
      "Simple is better than complex.\n",
      "Complex is better than complicated.\n",
      "Flat is better than nested.\n",
      "Sparse is better than dense.\n",
      "Readability counts.\n",
      "Special cases aren't special enough to break the rules.\n",
      "Although practicality beats purity.\n",
      "Errors should never pass silently.\n",
      "Unless explicitly silenced.\n",
      "In the face of ambiguity, refuse the temptation to guess.\n",
      "There should be one-- and preferably only one --obvious way to do it.\n",
      "Although that way may not be obvious at first unless you're Dutch.\n",
      "Now is better than never.\n",
      "Although never is often better than *right* now.\n",
      "If the implementation is hard to explain, it's a bad idea.\n",
      "If the implementation is easy to explain, it may be a good idea.\n",
      "Namespaces are one honking great idea -- let's do more of those!\n"
     ]
    }
   ],
   "source": [
    "import this"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hahahhaha\n"
     ]
    }
   ],
   "source": [
    "print('hahahhaha')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Python 缩进\n",
    "Python中同级别的语句之间要保持相同的缩进，不然会出错"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unexpected indent (<ipython-input-1-21aaa123912a>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-1-21aaa123912a>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    print('hello renge!')\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n"
     ]
    }
   ],
   "source": [
    "print('hello renge!')\n",
    "  print('hello renge!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Python注释\n",
    "在Python中，注释用#号。如果有多行，每行开头一个#号。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello renge!\n"
     ]
    }
   ],
   "source": [
    "print('hello renge!') #这句话用单引号也可以\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "367897836216551579269262598478356580455025438573477618640185661384561636087475052367616525629332037256703211092836656959943269904441990124368367041406078824495819854268002424255555444335135100920140691342004233426319136044029316392526315812190590180921511167673409761827801276725722507595583046456032032588292941960733870041763798221674162608937063052781791985824824442506788210703204050499213369394298425720926723339110849607247413357323032904135062130355556264406158168948977334647581238286163076154267120642739966519525481887066076129995336710923434329618524662094765530397182599289146776650544970280043953993162936078123228704485249710304350018443848456420406949037000990953034131733633445944862511489186272387536873328418638270704940941558617319018704477958713341395471916409160240742304027764411634482319669478049610882909386039454401907791397506419566148786359635515360197769689464706079607833678981890166470093671178054060158802784912035750280420612577539053039544972179514355918570113098901967397341445816243245204415314177142847007726657967190289059833436975762814990792532580448612375931365743119927691129690998820687504503928420430722300763104139855171801719448550611826521737842435309032776842283993666123479718766866223302243276591380294081293083247339918645760044217177267682761558945877574898598694311561607991848106253578393276174671929609562650617515772898417003097191667450831679968377805408227681668827590653854321786623325380234403265273689197637702247018807709394258957009112168035211973664496920440703063030115839644246463696386191944763319088230692290325523086236103538285676685111732690841426337655044634302595908266837932074670976663915217359354364517499864266686189846909317906520273898067458583826987749454652962830373245631806936923964346858429220292352052184365434539456431295403661243794158140486016793300991356023759233754092159670108567850050520775592509541456827281148478134124003179075267334553374232304997774983652725123220461484452989682923525677594756836257401936879719331260815198859583534133198726368308511469307436427700770797520862885248531329991271570820748096711231591929314996975409382136691476857310198475367114969766469642706173219555793668352974497293467254951090088185898577414668924197561827713668844677194621642555666188399899004313364159428553251478501040095109106025378890407636204854238717256542187219331775009323932834896888875972728675139657715593804142372659541049027312536522366425687041101615529027138338626976383361063752767964338643061515819891109450996910396266306006862217275320721215360681386806036715072368437666812965688854261434837474621769902903983404920040783497653045710474067969399886127892096748090124761086268431764032136821862629503843625150163028746432790672627023420856027115226910589965709413524667118469722228140620929374834535255274401791047981249013291991515312076711513722563588614518951993175015062919970919924635854254770632451241373071598330396121877701831665086024236270592022369530329429205452705612492919992138082258892336224549720647969592332714135185352716942260793463990398669774207284691092270879730217755252153719827333541861748250492753447728361311032713997900804346774133200396994902494750069566532011133669093936138813275408539045720967823085115723690395339545633020597822510443452328396090982982217532175659319747379559748277844738896269326163254452114491495049086757341839326407699943952196236498673907653552683941431284856361535039573557995341967802098305072032477186062250750688978720271622099205579846172519560752189611740570584449716218865106028462489695225428474352141650247535918074568372568363789468516578444370139672657609079710000178044299651969642333702859069003843532654337590256660307309573010289336460498880625010502121936817937064239451654852866171069859961614066939156562848773729839336583563812005273803490684526672949696039869693523337114566034011978114158541756045107886203602185828072242501675370254190202051434980376920526508278818904017049478738305342313894771837358340368795311165670223200495236284522147145068001354554420451250498737737106375185795213396533828745566540977156187111167167920796850806737308309284158428635614069321847039277550401318214903516990862358779149372013786213321729469329412415100645696467871307241338445521385792952808445036566256794629792646098610825994187555721570565523519254013269283129307657236475799320818104323745840091370870554448283335041699183434655317953691701928055525238770074651096779906700811990524113280961781489074930946490800023879387428294835998450575385456910157782333465350254086121776587106949004680741294259098039582298857088313764695660070039039914782877247005189527784112455291859069428047652051005752060496002154812418165375739103740460652323651937788367444193733591696684221644330661875384950637908172837196588590801765407563898364167366508740983504026411922766442089280367547491254391167581896542071648678885657410649956374561799781552568746934517571701964068008178419225030799768505259056106911328778564722402413575957735576697525877294463464918611027954897747810424943138531841721913893065120976371523538004094701921885493503979156726345843997486112367414222868986535671141519134796114395017756543023765059797919276487741748665376602131613637337370026460907579846964912325326349159768093901930664818170342893519799144200734502639624790620040309448612541064509192862999745306868118743754343109186774413322603862400053033265720665131442280385458788636149509116890993518118328530844574517178396009479789271122731659273156726676703359660357605739485296596550645163088307455347212434031479862416941950188057557141237322764710699744343151306166216263436430156659791499212666637966080125668174706412650104504271903725464592246153229290737366875007387542152604369029180288053404004152546615733768503453135845000044084600197073400097774197951988576435126275469489892858771215118905188637374505602479658440419586453324092906114948893174179075121537142186000190800212714482856964085324990689919036527641730606795954016494448183172366075716827022999608857968247722432232331147397862964255306766900080809686595696157871320224796578079207892386665567341887542599868430187474380818565247628957985447790230659110690902418905442835322086182567376144279561259859875813383025059370233957359459374691970809118294767507121683363676317457440535349495595560376000385183591675107161335853555655135894285636422139325255586571919947845960499191415587580447354717701099015640285696762195282450472301279076383837849056928905780326976990887181130808994166485311360786325838095290243070607306780722376753433935871905384627849281186801272595998769618076120355550215848128075244342442480440872833619450730612053799915467696067466161888575965609639129102208475842280956448019964285078621018270025797939122637546890567604389443730874634227818668280385126229585925169556491976830773813558706028912398113593528801124791977906563126666388702644378126886687090166827312828171454634351758876279737408862782551142564641704339676042941546045088198844231690524952138109324931388288260004549275520313714023932692894851571053428678965296557258136165515192828729848927525308062656324926761561837440526240828628826704544167026690099680211309263575177654919309507167729557907160812878432966160174340355695483456733835336149912775697234975556747137764726824552038391717720505032050287177852966290669236806368494881186468627491145022055382087787554721854588588263408173561637737320503265008368471560714926202584922299819572192755819352453894888590798367820892265485843385213385018771814596636295280503301480878086880873335365447369258804452075217137119465674514405273647184746897898554067575323417985244608476076377509783505883945366948774389545359021732131425973101313117579520538560942172432774922758836792314944762022863501800793843705903433843336020405673631162245373258583714402282661325411562588998220291133296802993671979333156798042929869655376277384852136563986936267460208747718173110050861490123301788260983740710213458129287496621668027723959647710047128506017064650423923042914450945366190430528939783154286711819207062967427253305601961176258016375740569312339981287380471543167409758703595179417093942111075111201907565636692664926819820783028057942877645322805099848984626552111019839259187890832537526193130574418761250561193038744373005492489071458752336451773336514490646537511010773900333601480408706476183638302909517032179433355547113881503632141966279444110935982113442486475169704719991232972805187252442805986457774362920106339557508321520595461265138096577135698046682890070927505212042726253476086256191289258716265432525722534591843335364000858516490166866796456446179587191305724300851055631659974967100109390455589323103190258994864372321212506768850683234440640158012936660523491185485651348637111222690075918534119967711254246745992929897375534228208373262175929355842534138305058928352932713066782490726627366546674208197956620014542292511468180381057184142771857954644335457939155876777134244383207268641131465598217259704029327587369406615798157527118244893011880073415496838947612749445854675657903256816120317436586434716125581206660854237614428873380444294692140958935130186560071339212815383847348886896466017899323969788439660150640562294498186820985986799625187250425479534098317406514933883570851448222574401831022091116432356613894482948034130160997630301718762075575729537158086604421635607571152339982410647293610492323843274872313334557278539204388230561543268261974257895035758985348134123022234593463076076927384115568033523183121900267347104516449279828654971777418142109834198514665598785350791593996084415714027212821944056200527823300645546363125041274431971815727307276579013988037454431734803124255001706236214509445748394362874004974136144649285143960042542541969530860965617503057110972169030784358650374108500358755723554400952669976337219527428033483966886475436215680979691175432617537090426022591531545735602213325314954645432840849512878744812295974110830964281537342784394841272679892489618875140746323881213737849782655213329585698923455135001687940789069009962640208874828153450263835739789982563415815012244504225309744804774556983405965340130886675341216145958995582714297739765743594657104777747974808687021826494213841239238276912644576932106676010417755104869017057675628523503784019918854268238310075600006820603054421972275114252021480158611959268750766192903778537533704284170937634839390736619864598108899298189525573895878944263278718064010303702755210307185290818749764720345889100538295716032963028204717192278452237237825524317799029642605901704205704737881687033445814969200146695781216698478926776386233817714670755403983902473473426762908541776178438434732718238218589495041132974928247254461192982882763557341864438910655086872463307573235311928856506121371404553393675121685394053889665543323764456082643875263288252508743475107369517987555918048202956602520429900681515376102898278201271116267429763710575166418845225830510994323155681354967840059803491950044580670352679495882001793120474940745038089385839186192074008228883380933169159966785092462995205491021308512923892205783536527664751583796014840269644266291281884295845080069228046507170513541270729933606991643132798062136044836304450378945676823363950807962765624526962363576833588024683083670049316553737633211197164721927146844105024266705159837616026444351025175687171682340309121910888175213105183687867840597907369373508779251398444847745541207331092079325978196135407337013597236992549632515704426825790527701100213984532348237812442801083909318740422278467965298943285157977619027333257618685730956583944773078782592156968172069754501756794831793301549474152030114028789389373607433570547715053506847921522500459322466592532464811584480329903904332518221392691051252785936100175178869639366297445640696514640430428297614820551920905905924357624232190616757303894671448806951282916034700925164292882166865428509374092525376125099125495606847776485091708428258489671122514943259025497759916127894786648030103320041521720296749857433038688574563793012008585669838390712781684191758694112729240693190387952710525798511480938632940759669979507675092904773108090967577795012093365607454084201234791753817801984597488063036969565559799772078996615003213409233447638722680669326921394923976239928496670217810931845055582731683583241983638349170785061424766703972986683955614174539135341271956184282795741071068456306215704569707502406571897138898494250899082288084299821808305880697291877939610067864698124439862198439110735679066813726284433333463248487603351517393911584706411132639490542767068224623721952924204904958218239440720055895134178941683637340130104743241448149986819349370812583967590526965728970298084270763771475844137992281433137088156937398347023698542962509892366792850046923459735223504632007440974895007914884114982828368348023101413717783466512057605066763484185483710039740722253964238180924957056301246933405703545025628876354247386703599284096965507902979304170361585168375641807437590769243610504719934182050875972258678954333866915719263442682785954124568299544430341513003966943735163832423755891873428510646254197824213445698297004549151992987666219001114100521234651400859956343309696724633000440573361962287184481710069061284735244711043825411668023821262216889143476575954140919050222446186031051454182334893885694107490180247449917306860492180491148889900871685082848657680305142891395029813635134042893207265245894883399999037171237697189196199023058378849414389115125501429073253494711935412978983708353898795928522937655174001029406934421511698396735654539745117407425303634687559069783365818964959864607581829471918457434680416958629833536609562344903558271785850089447375767443999209164472952661588727748290372316738224595522660296308740425891401182676517770843698110337330858193094893232854587446305353287943496441826362295619015201870272994647667142001077380964302128471973361264570253058325176138498327909489895145745473593362582443287703131827006608494322182760781798927940373671947160686218313146434204080180861473590782673263217472833705104467959356797094876365938999775345890480536581877935227967013082820410112472167360410863575377835578639311169020047335493031073760193719865135288041200559175593455811519863797231031517100690445490191184147061469655929391697482891606552946600707372012737971231280019111383932049197870015226917546620253766531026187509678702305886229163580058778308923060212584558404124867464668917512663302485359492007455922632820913068621679904256769934687784503094808716173337280608284146450133007660698054289003899360117713826250974753336108010768317800911552066573981936685751641289218404594369541583050922567828870042143653263050482689570826681303145900798059656738922071119239848115967941920320798722077756263838346857690914768413841236365197618369167452118291100444070739371770246571062512479725307758612588675851983202066299448107145393833691569840724074183057420777725587192335446743491623349361760868188671433860932535693210810046073993413338111804144676066895227596689451055919654320161963818845085067581579518654524652364649011507134991573097668316527639939228279483338670275839119513619802191701222918873902302187414825631564828638504469065837098414375291656369075428695496554284881298174892659133412183525122628267832973552734346158694966087825520110453614750312350767391631527460679884385970069312890857582692045552996650331689455424677748512513960690869976717270073242082423921830085231499687151736296832799854007489806355970998944171036452913764317406042356199066243376639592896743169125566371672929056650339565685446712568744888193722987575109031488224282757938334876882369831521813664717587300432767766324088035804957177424274401671065267906322470578374354042257169907361083369367787826518079334416479631754401754312025452202368351478333830117231295097339480784632547797539260486101290774177620204035452132100524558501591217133729197782520695176889115926481330574085440668844390378721807154360500496531659588680830502609114531876183993694602386884466365660009013821528382543146051666913231504575582258022657046741262608620102520874142067519968083610195570543113898279215158824262380033763439303871267728133802158213092495137797833670066802581016839482739050040734986216548374187119780381210830980446674124348548678605392635109128495382948162541223276946282334778968403740464659396372510889362431869566162218077857924635332261796583798561287251328598483576662302971326674191816796191373479897437912084563951257870749163004045427976173065069911053245891792968159302093955625365948375513810480261901516087561646730851638820961501790734270792821554434606779428218578768731336682139008600245200512764089111754312829169566019459390415730069821854893165101887182444178946463170546487121214411371771492381005254312020326577901961341772173121948718139589188317269026274386806463505981341709668865461162383670631844525821041370859274943099195391770221427330517293197084482696575659835947637614972919118380548234763298532042329931180919301287653969873021567314139523643921403304883421429677664735417929687627482346183358384934797320027006323884786140035987146679207626114763243748944257138767176119109371329176077094919623463981395468845163202285057681161988532888983216992242029373774875908086163361779595994789551404172647889925018526947129770488541671285867630986255203248400734774218321663526774568475881627296831610209867157803335255628322800798239828675394213263546514306257943380023172172666512235854484768244789947461709400728821035975086956270844697968159770147940823436641972928622898979034902250718905032427484003706734004133648060061569802889209846810677262895167613024585914234634241210588796111765527398970606331828865607153526624583801943843593035856001519183631953287072209457926271582184235357546897261144515361838978964891330975183800355200941320616596335383643542957582832586163163333855739126701139679898552873320429512918365121465289737215878314272746704579645684589279936194896798502497890465891901615698742195426387903511676657411502452987032506722294146369491882472121321458765632661525262593032289328410513432654222851516609747922395974987308488504980878206604069401404810502109494317038254871807010165038929614766547664936986364461952337707271658306297182217108216300877610531544039337599218917423285083794427283783167181479191388627891750281937912661460989656505053762371193727012110687869030454151619706304157698647544284916077675183273099090834279444222375778209438761027129063251373889137916046633870295907386515923385184064268314069407466444924421788721765573145691856125355337367930552187864910704860616095506570304282364998058507363678784481655045544898695898070942732631423939203116809071450689869029713382458159357450447680672899033840615105960430898441682075002495493066712650792577417575965813338161272422819078156381732202396262717897020388636099656052257949298129246632831806660095058740029209496425110565062369369712384921329609930920170748616662846680646260721905942083136752731124621965012979854595775697943404133340843197146599994281566968867510565331758185215149135081723509421111587238569172668354092680754017446555866018639926714539437073198082314023344812282385431353362887571419356272792111403113571881507065449136270486474528305007856926999230051944128338323756329867894777348206320221329903840194034078572310066783704735739417955183950697204550874547056055446109201434434172057133394117395547130535924308744013687572384253935198127045630087776673391794184770094047043312981879532329663209773324510123084014758130577399796333442786612995503127690728852849893787247036421846094787030815975268412542776323373802446877277254712923897294933237342344021718907065248418380067574201794330810640112272875432748355702136011116407906181154150171645197532163289077828150737731615108158194692246544779680695228972795843169915533018246311833120137296155274771643144645540937746541475685196938970643929000303159884435270075447941254885928859944742410461115348088493020710430847268642681060545414264714412180463048179930449129575976981685868759869341859870675154760366316886263500681070825859532932708778815561276433850372980234072303045761989829376070324323901168454515819714052716308245263687834157368666396260473168438656431939869673888742377005272569344883290608797787499523498305020075893111876046521474078571237083716369710984419772049442613266190766883359064857141780029647371939998931959305988473442988541387319966547543168708786238307403114473458486077870078927888310399974909786761614307766787302830942922746653100582049599204273565535049683740607902603360469275442532888697388509494417045447530600755750714587564338775589083763975039059826190435030983989800213755014707251253904320085269485443579603163618762065785639686242441600625359144519791855720466490427267875054429009486874943194191278814763393155792234250925337711719065720258263732394029272067312847753088865201406733072803304731628614799935055471588957883441789320111085394432866765062722951844805464314130278393957124641220240851607818367202177253954457825116612401349774171323766388292426309637031196865088759443332141979169190204969565774000115992216370251598859724235099832188775299416962773560952063233936686878811836406142636242986817408895700940390660886957731255821807028935966208226762929516887955706231387610576178242755056019436671511236191386242905621767282052576615761421171010410963681186232076896470337148307956497163666318834663114680632416873817683369766820339426755431190375588053862282665660688460851887629249424510480767168977226568880273249773931718446631970516925511140352043618719432080912461606118328682272584997236027172439400639558926587237472907544512369217123648368323621764107204103359157471885377024576594003795377597244539439352244510801250011085779297419674881778357055124726633061957916990673668085532239919493569008237949452987531858733850417799530815393957431121904701131165177538258905489901351130667898257196147772794550947275427302676250555644696483526810870946303688571294317638385542195803248345875375575274321720681280090635867695218844275257436917090131235379701612182416868755554992808503694293457486371090982563442128544071310822987748396572745559152361059879615757507310830334393872793585669561582120479185108050076802222796160521147238264135769583837224255089784037791158417899828814641484271188275087964461365514179125413759895055959494360170816829438302976512775503256555828025775039686803821519103551188486874124448433279546490721119400638156202597976323186029358594548443630780568543660529649647111516286612403641416002144087019911303520528310027354653442310783798630208718348760887022566014343477620203744813135981656382973257869618012372079192639950293427351455118282956901625127061973992792664547509495913412932153175774825508770416767066672017439478919309651956704430975487489112061047220288640551006836422263619154651209112297574534054819289765254708093578818562517033284023521943427960526087726666239438931860444451250416685661218363459823642973160666965581634293984097304199632308817390488188547294661329164037122739640354567405183402584586456845795599084495213069079700707611065115666315166224034967110630304768355224750630674296463922218938521206008817743366391464990072012320717170652620375042093695849498023917336056706166775837952012220604016840913687411172624473164239922614912723487379702427524301870033089347310243856685375825179748429617271767368492463691404698883618879587898612987892629595389617103849960965170211874087663980960150715066420588792980194455334915847086447444462213966723477798020180680532346201029916861676974524326288330892144293782748761330202500548190087343978357138576669830568978698344126102751355346408434882614819704070962087428612222591910472953424702042456122173122364904328054091618583161254896257659568654303031691849333862784788592389449737801452357257733030126856517446985521510569964667550800350926252525435993975621762399031718237622306423422304350948090797284594664526476958322858121895687918289724359983063037495666940121538732990635715853373864647509850712170033343209964905785962697765530309169611859339999739825973344591907224267482381091355098969487917475646174496452265365504271473024485675356758685800675455830744041713196175194082142711680025197591815111547227980870941150478679487323395533557931246318504475881363437170259948705432983846941029007056480150072937318665222635386970190116708391750301714578207002952383647178715794295363809683789611790258101510349913675751334696085769997014878498222327343789806319810557010351793479510414908602391816891361003552632513550325399022180740677157086312206906438882528167445334718289719520560108234866425568854392980208136381094930176304290931061862767139519748040699912964753879852087827880338338361492178003593768027110580234336362459158334742077867465192404767625937709393781714642847257864584751571995088741008374001636247779544194748083568121326808213855664690052533928408636164867719562785249954111378651637272973927210866793383399006114014423366872721658681416543625798286589702506418328169117201601753613705737453944630217871486549855555032347233437354609762153116869912828294068880549548026940268702562567708161971213469677017575886570241885701080996725584277751564158688244615505965370493230241602505375992750618799035427045849613273425669358640497815135397248333071531676644224422656435279641737196966399347241568022890593766269984820480936867871842081917426758980285987590467620192766237486112075847457605045356923294301763804050160298437664745329780709195590488223858245838242028037295026506893983276785456369778362423970606940674686367078430868702614850399545678945157708162518799186363623549005121926005321683329948178176230907748865280729850256780003166729064230716191622728638985535676498318906422960462660894388529285726288581022746626642566601251177270514419754719321282580679278624078858288851673229428436308874321645703944203722439592211803877969994432653458604541611263638305090993697388252972976580495845395780207980217474039960454018269036749185866024810063396555587418050209786280386632476349484509882003054440674105565148760362037487382854375776996133970530125017569670539146440964044988818873319775997290056140705341218567576381269406917764201360527763500961821294366966323777837548913772377404947225131220038176873737651067306444410917558997215022668711668388130794276328974688922186221791942001429604400851724231871749019794887762789134973203942854250359291269837379915210593869235567640319180310355771053251584386266359909493884881721219645698021695661341407006640974564913145193032816149892732266443133807011962438154097564274545543461711900859810950648902814039369292510616054910271550661366610077635373627527629987059143438566167292417343423524895012442594852556593464894133309707631676899071185563909176779590385500003727136618106014796100922377066412630591404756209994322798992072793055501873414285927596783601950448789582798182674244365009639922512035298418435286774576472045499230546794083730895850552934247226523730975403519469811812338806699296341387529303471178110543636156583488200199881047212479939546023539235127577320627857430130834566144589827636688994719429333121499498868642313745223648865877785146192497889037753047291305156175778181728260374785919719390983930023409130571797241833878607762790470309689982306670659761961663055944185210355162595808554149780618378871060252320520607542364685604068778315932873499797886295477740252706319878860420903965466386604104864823238478390033394355868853172949561684546196697662937270348975485835842890448771603254736236034319473571566717572611630174054228200367538668856717304905766935306176925720708639877116847856828021653523994201732568645148544653293510859448131173379260056560610931807935423240759549695354494062778182213529594989292726333539226630058394736023774515373039020683989040713994988340956751827162716243873377149472488142436771261105239420611228269525985514064409262449202592860850062478993279328944590111793023056098592706527760109590747844821485639490847563749048154254812859204331572188008956526806715622508461643167395788480766986367184039715145241282341882723247471847617137357268164463210151949549527140854153814075363894294099586079770005178628825535405726670681186954348546391559670233876720092543995683298199596839908674366449167832778767535803408593001188818490432173962031376512202449133235714988160689923854026875056672340289219365048026041315073611610762001676595464690940127537805910287641813503830115242242261048363681215295247566809524799656870352924893186324582865276105138039117643042106756594663111494365116060784130794183641871418921934495594547073827637426599214864206862293977410104291616729991343763174670395896971886254067332805825019291100730007080560386102071782626692665777630830488535383441536503418703831766950563928800726710215440882350055538177362204255286927745052301285387174072933785484730483717891203606197829395618841947440273300655754254989601379764390998506148348575327706905362153884687458710552084029904453422668213731955434091345553133036016755809057660275071884670743857591318644907645248933314380711652624286799447201911011383787888995210749816055482071714617424035655060029191492430270606714323051629465234753017798805710307813263150272236197573942656746356366462524769889675693158309822111913587676284666586423774869438514168649694894248270919595072213098439485311229545135418983812912567841659645130081666603659459902478034667968829066957956864441495732597658077759874991082017610474068803351514618038155861898106950613132662665295439182142899589759387674454422832137058844343016150630162037042625663610284366970574550868215972833961636336850626687942561160445088652707193654717322498215669665239655937475562604762694196270617255238727997191532425447687467236878013255325158944592159246456927939269132679487397304463618340304354909713198209500443331474767353153648519748868131418502976495410454244586212191830743462036936484355915880748061973398703124140874324146478832721307731530203604847663587758605834926589052757942100701764976451638198954952873833544697846556941933758082498133969635734384019023032180573995826359287998327529864231425521543636597599523312158991747580046172877614050776387305687667163286454820561837441104876742479085873175473139339238134318995058103859266829875270500476866251862438016251549077085245053922702442143991037790354535678716743799013036344259608491670782480336122223617259667478656589088044757108983296385177965073462662810064131046734378688998988261065644054092319059341537771549235360782263450031511188074028900849698309673542328328516170830755971163602326935166705391040355058393879467548567867698077681308803761126274314854409286300600528686848035639284534040808110639239705343174890750002135570808439228299892525429503026918762969939400559255178903953751686703671526605166081464522249770934517641595402804171102613908111568859238221168547601319007532789729156810586108005576627599095883828778775149539767134062241957307940505789131272226240521951134206211156440326629297030853637479179925666584908777039047094847714351278558089157845966012040765739689672032900219358367207916803829600285603983961810269849118221615251830446551403253474809171951270107753986228097267712675781533282169045313116584476727784349603599257868313529213214461906545398091944726465972028075797673487557346165456106973772681924753593860311290655725147993325949658217616191524669915494205122343858864605076627333625247337785086180208540275162676987828873353377039134464572888478553385170433600207834027112067602068286957758348337202148884442514577285913805013894676423982250423500189067932083605077266969762368734881465889526311663633171613931710580878744515903189713307166515913398281029975928585786064834541749733212294487465147357735477484866671691771588474512165063689436759570387680781964850367342992732603379348372590931365517722908839002571408197441525727756431374429742364162175221789578038519036488749736269018174760164450967472512599677691561220467128204489744274011693653363437458635908410031953599283166993516146352993591128399767386151539927151466022837045707167637064524710293755218114658769470354103554300014543417854839100249155181709016141993343230764558059929293778887716635743280789446869972806782456558825124577325609738140586659542224316232892904765144378151201181766725357141229004726621657773432766008466598056627005251969402037460953635554567861508476892187819643924182419265642538811560358165073845076913637342095677574096219734892962536115571743317518964968821195459990281046437507106756706238224705908152245637268644079626316710639308977658072630589723338695104672016438470542275744651667236661255511371887662205262492839874477802129490011928141856009557643125311662416892270683584929999947085989071675729913176684297872928197264175949078131873226885354198482618537258360543400740166825496051919564408490492856274390044905003682719796601770332921571173437171554903037544799951180561657574953075787338270131701155451095351824519636990398737063047430660954247379489179715715496995225002169154562117291966057004257359209341474815741646465352148895338326888377248393316325738584267417124427334245336463002935549285720262130360031355581045620680493325763209392550013268330481839573958556217051436424927765316419843066077390087270983634758075152495706125872430606922426752980008740564090969897795564894858898375604314435988412592109194365722333747027603556604980549685018815642924268627638121727609033678217575217775947686392090859011318611608582782827155639809303088107928661440220871550096052795725401813725941689341195268278666458922936755295502579831110119466497205401599050247519492829559437977641815305271331505401310392056111280749237398932156913127567400543259311535940704469690668621124370247255921701655549999026762857485445367496949808090191856419454241112763396705499893221700636188840056465058933958379530976207325428306092677651308325355512686202823319160821009623284204021529461414560165937280242653387287845851596218516164020555579111482933163398011044894075317290499123432393586151093954800098577251466437622527398927281499599774779167933763077558957842196753072800227476113161204707996310282286238451494898191751590580713510508594911716632212700061602775970161760826415217339942512678749515512254548421351105647811610065528914715442715696466152826913179836963684554329786100750837693743710019089869445990046913067690897215345960143954432036865828751508932385400098607229747105284073515928152970898105817741586670516096461265193077075590634199612419680360395171297261876958774278022173889695705914414239078826325988798043953840017038839579661653022053803577716890243800565112078751049090332145659390873818030524266622468326054528658620902062666218005748097873478983423144369046978571928117717385276687417716187108616987123774499034647215876715782234306435333164675079446194889316907546812484199283393347649204259237843109652317687933100325101583876404721129827305720093662941540408611916130055069233659081522402514922434475877262298010773081408720868113578056000668680477253256293520188845159040198667171627474801042378849343235759713002005441056581844837705423527700097371063355755110173922512057744570564756127898278302515157007841989503697831322701439833816497751504424804608732695501513371032565680988460025951867276510452337278245926183915653569880821156264564508373235561237676316141274903470514459994467435790321410086695485919724808966676033900217756668003159817855275256250986014709476119143947767409739058294945215691836749279290374161318428518365471612659021196856686777466136510751551986411786809061365465188499063012594322877923093504186689036379453405521289583136867654967483237199426783433163357014947584385860691305485204710552579330291356908310501927294413707409461129050706966262790948938237736633461216512339366613971620671175899219792380140832407745351849796287041353225698048731026857747249212313486544523812860659330695423370643977799197935477788082634057183851094272267658772403794755266137893564465355153813180791780557231700507926201289703984788788492071002028512582749825472754184745457650531114176770148422988836260829392207317234174018573135662534196991903126909243079323191317552933922527589349789276092813741791873736079125778835873045509757661705341347501673154620211257839274558686731713588011311582277639665525890727697387221682975083728482184110313864606434588260860403300533221872037664419299682182074407080981670479845726841896240908842714019900476042901664648727965080584113753700548611961829894806407932500021585364032078236513072412447441347631533042308523137492672928482105436919105976764797403252870893269739804369871025237554175637863910915330402871995151471218941901453867078363245710956557273797870644789482317625644747154541510619557330352496820184835634704698834982264971159631482467256940151953972894135376558654533215462268962258534274514370420185174748626135945780365161414561553362634340610873957275356408753096564652126286908381160784006270051658861660398466662916317044537581858431642417255850479866611976544514725923534377804079528527621141317345301701226336044919926425342843572599167424635331392747767060837316924372603567094843792441469244052666465124750650061681302999564523234906508419405293271972714298888238312793386009424962634545066177491240011021643773287599897519020453433486224289848048337373767013300516229892719923552542806918986920571734697496423264937130883964327431149925618424552802098976416154250640428397494085461169438694922599619734525873149107950789188033629760316581717242867307575806296510916932153202519080164928272938983619623111545347162314320569176384971736154860336073472857942316286295154509916077758864702318222723448089664306550365217021740838523647857513410954524727243009812305808517591167549535353946005845352472835875622220524598833338030186918297225718121494930205993261577254430673092947552400172866472533430470608812655768965253049386012107826497454451387378312515587063543264569718520739584333075899262494880263279844051210572168038532844943561732117048602342570856388941985300089682137977209603560403303166886532565337854804562096492073505290677729084666115624243112767016460798921535882002129260898427550343833531563443197967161245610772802405609273254358595955774665721541290752108786685800689182591403052130270013316900112519989836136375066604757046156214942198140674564486229689441079936894295870502092970164056447525812698631102723471099392031688226933500157141747062596402341863792295217106130903084117417492852859725018677000964641482851821561792778773961247328211685101588179047899448438244386385777012058218763852119178155971210632776690655430175180488760557360380269094953984589565634291338183426395488201727988288617507697310364408018640130502956409501524451022322299868243207087061672539372096696847248145829940649046634431518312833815147214357565954157986423553259005051841835665128736379792318063518848999174688403849726500534046471678274191981527137896434425627431729134301107519159837216561818479263356367461123733657185545882806844238396343157654459135963727932187184542198914269053874714876917685251510299180841641400508116351885043634632905596357611941519252677119022356216409736743532305444371064259983202543714712431095736995734033145555359134476556396814166138322218239069287103151334338578164520896978745202793265752406579178109718820431975663671630226958729453386531280474106084280718087691441158725271781954721968047646223473347562066999002368482632283633426521387135321910476075916925637209509763423532152879120407873322196059692648795532322379223354627814918607032123848715018930830727202650353207571043352342072817045239123209005599774181886895838967758203566759961750091960355682364854605082885291636596530613041299493652451738246725034844359534200806869482207232344438878822955808502575907536033686363493341821706253092253578641481940268219048183223806039330065132058974249530665184867744759321689979524191954229583611011655062180610421365705288878247566418691431117632597725013334430538248782772677647918168573239772768903351516934043293727190674999916658341670000499999989999\n"
     ]
    }
   ],
   "source": [
    "#有时候也可以使用三个引号来表示多行注释，三个单引号或者三个双引号都可以。但是其实这个符号的作用是可以好含有各种特殊符号的字符串\n",
    "\"\"\"\n",
    "  print(\"会出来吗\")\n",
    "  Python是个很牛的语言。\n",
    "  目前广泛运用在云计算、大数据和人工智能等领域。\n",
    "  机器越来越不值钱，人的时间越来越值钱\n",
    "\"\"\"\n",
    "print(9999**9999) #厉害吧"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-3-c154eab2f614>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-3-c154eab2f614>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    print('I'm a boy!')\u001b[0m\n\u001b[1;37m             ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#比如如果字符串里面有如果有单引号，就不能这么写\n",
    "print('I'm a boy!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-4-13c8d424cb2e>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-4-13c8d424cb2e>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    print('He says \"I'm a boy!!\"')\u001b[0m\n\u001b[1;37m                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "#如果字符串同时有单引号和双引号就更加头疼了\n",
    "print('He says \"I'm a boy!!\"')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\"I'm a boy\",\n",
      "he says.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#用三个引号这种格式可以完美的解决这个问题，多行也不在话下，基本是所见即所得的效果\n",
    "print('''\n",
    "\"I'm a boy\",\n",
    "he says.\n",
    "''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#所以三个引号并不是真的注释，而是表示一个字符串常量，编译器不会像忽视注释一样忽视它。这不过这是个对程序没用的字符串而已。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Python中数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "can't assign to keyword (<ipython-input-8-cd37f40e06dd>, line 9)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-8-cd37f40e06dd>\"\u001b[1;36m, line \u001b[1;32m9\u001b[0m\n\u001b[1;33m    True = 1\u001b[0m\n\u001b[1;37m            ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m can't assign to keyword\n"
     ]
    }
   ],
   "source": [
    "#python中变量的命名规范是：由大小写字母、数字、下划线和汉字的字符或者组合进行命名，首字符不能是数字。\n",
    "#命名不能和系统的保留字冲突，保留字也叫关键字，在python中是具有一定意义的，所以不能用作变量，防止混淆。\n",
    "#python的保留字有：\n",
    "#and as assert async await break class continue def del elif else except Flase finally for from global\n",
    "#if import in is lambda None nonlocal not or pass raise return True try while with yield\n",
    "#python变量是大小写区分的，所以true不是保留字\n",
    "true = 1\n",
    "print(true)\n",
    "True = 1\n",
    "print(True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n",
      "<class 'float'>\n",
      "<class 'complex'>\n",
      "<class 'str'>\n",
      "<class 'type'>\n"
     ]
    }
   ],
   "source": [
    "#Python经常使用的数据类型有整形，浮点型和字符串等。\n",
    "x=3 #把3赋值给x，并没有给x类型，因为python是动态类型系统\n",
    "print(type(x))  #可以看出类型是  class int\n",
    "x=3.3\n",
    "print(type(x))\n",
    "x=3+3j\n",
    "print(type(x))\n",
    "x='haha'\n",
    "print(type(x))\n",
    "print(type(type(x))) #类型的类型是type"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python中的数字类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "3.3\n",
      "(3+3j)\n",
      "<class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "#Python中数字主要有整形，浮点型和虚数\n",
    "print(3)\n",
    "print(3.3)\n",
    "print(3+3j)\n",
    "print(type(3+3j))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "二进制: 3\n",
      "八进制: 9\n",
      "十进制: 11\n",
      "十六进制 17\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "#python中的整数没有取值范围限制，只要内存足够，可以计算出很大的数据，比如之前的print(9999**9999)\n",
    "#python中的整数常量有2，8，10，16等不同进制，表示方式如下\n",
    "print('二进制:',0b11)\n",
    "print('八进制:',0o11)\n",
    "print('十进制:',11)\n",
    "print('十六进制',0x11)\n",
    "print(0x11 == 17)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python中的数值计算\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n",
      "6\n",
      "2.5\n",
      "36\n",
      "2\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "print(1+1)\n",
    "print(2-1)\n",
    "print(3*2)\n",
    "print(5/2)  #注意结果\n",
    "print(6**2) #6的2次方\n",
    "print(7//3) #注意和5/2的区别\n",
    "print(7%3)  #7模3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### bool类型\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "False\n",
      "False\n",
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n",
      "False\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(True)   #True和False大小写区分，不要写错，都是首字母大写\n",
    "print(False)  \n",
    "print(not True)\n",
    "print(True and False)\n",
    "print(True or False)\n",
    "print(1==1)\n",
    "print(2==3)\n",
    "print(4!=5)\n",
    "print(6<7)\n",
    "print(8>=9)\n",
    "print(10<11<12)  #注意和其他语言不同\n",
    "print(15>14>13)  #结果是True，和C语言不一样，Java中不允许"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基本输入输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你是谁？1\n",
      "你多大了？2\n",
      "你来自何方3\n",
      "你往哪儿去4\n",
      "我是1，年龄2,来自3，去4\n"
     ]
    }
   ],
   "source": [
    "#输入\n",
    "who = input(\"你是谁？\")\n",
    "age = int(input(\"你多大了？\"))\n",
    "comefrom = input('你来自何方')\n",
    "to = input(\"你往哪儿去\")\n",
    "#输出\n",
    "print(\"我是{}，年龄{},来自{}，去{}\".format(who,age,comefrom,to))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你多大了？1111\n",
      "你今年 1111 岁了\n"
     ]
    }
   ],
   "source": [
    "#通过input输入的数据都是字符串类型，如果要变成数字需要转换\n",
    "age = int(input(\"你多大了？\"))\n",
    "print('你今年',age,'岁了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你多大了？，请输入二进制1111\n",
      "你今年 15 岁了\n"
     ]
    }
   ],
   "source": [
    "# 也可以指定进制，\n",
    "# 函数格式为int(str,base=10)，base表示进制，默认是10，\n",
    "age = int(input(\"你多大了？，请输入二进制\"),2)\n",
    "print('你今年',age,'岁了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你多大了？，请输入二进制1111\n",
      "你今年 40 岁了\n"
     ]
    }
   ],
   "source": [
    "age = int(input(\"你多大了？，请输入3进制\"),3)\n",
    "print('你今年',age,'岁了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你多大了？，请输入n进制0x11\n",
      "你今年 17 岁了\n"
     ]
    }
   ],
   "source": [
    "#当base为0时，会根据字符串推断是什么进制\n",
    "age = int(input(\"你多大了？，请输入n进制\"),0)\n",
    "print('你今年',age,'岁了')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 字符串类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello同学们\n"
     ]
    }
   ],
   "source": [
    "s1='hello'\n",
    "s2='同学们'\n",
    "print(s1+s2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 通过下标获取字符串中某个部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n",
      "学\n",
      "o\n",
      "们\n",
      "e\n",
      "ello\n",
      "he\n",
      "lo\n",
      "el\n",
      "olleh\n"
     ]
    }
   ],
   "source": [
    "print(s1[0])  #h\n",
    "print(s2[1])  #学\n",
    "#print(s1[6]) \n",
    "print(s1[-1]) #o\n",
    "print(s2[-1]) #们\n",
    "print(s1[1:2])  # e 从1到2  [1,2) \n",
    "print(s1[1:8])  # ello 从1到8  [1,8)\n",
    "print(s1[:2])  #默认0\n",
    "print(s1[3:])  #默认到最后\n",
    "print(s1[1:5:2]) #步长  1,3  el\n",
    "print(s1[::-1])  #有意思吧，倒过来了"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 转义字符\n",
    "Python中的一些特殊字符，可以通过转义字符来表达，比如\\r回车\\n换行\\t制表符。还有字符串可以用单引号括起来'haha',也可以用双引号括起来\"haha\"。ASCII码参照附录ASCII码表。\n",
    "\n",
    "如何快速记住ASCII码表中的内容，记住一下关键字符\n",
    "\n",
    "0-9对应的编码0x30-0x39，换成十进制就是48-57\n",
    "\n",
    "A-Z 对应的是0x41-0x5A，换成十进制是65-90\n",
    "\n",
    "a-z 对应的是0x61-0x7A，换成十进制是97-112\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|转义字符|含义|\n",
    "|  ----  |  ----  |\n",
    "|\\\\newline|忽略换行|\n",
    "|\\\\\\\\|反斜杠（\\\\）|\n",
    "|\\\\'|单引号（'）|\n",
    "|\\\\\"|双引号（\"）|\n",
    "|\\\\a|ASCII蜂鸣（BEL）|\n",
    "|\\\\b|ASCII退格（BS）|\n",
    "|\\\\f|ASCII换页（FF）|\n",
    "|\\\\n|ASCII换行（LF）|\n",
    "|\\\\N{name}|给定名称的Unicode字符|\n",
    "|\\\\ooo|给定八进制值的字符|\n",
    "|\\\\r|ASCII回车符（CR）|\n",
    "|\\\\t|ASCII制表符（TAB）|\n",
    "|\\\\uhhhh|给定16位十六进制值的Unicode字符|\n",
    "|\\\\Uhhhhhhhh|给定32位十六进制值的Unicode字符|\n",
    "|\\\\v|ASCII垂直指标（VT）|\n",
    "|\\\\xhh|给定8位十六进制值的Unicode字符|"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "haha\n",
      "\n",
      "\thaha\n",
      "\\thaha\n",
      "这是单引号'\n",
      "这是单引号'\n",
      "\\n表示换行\n",
      "\\t表示制表符\n"
     ]
    }
   ],
   "source": [
    "print(\"haha\\n\")\n",
    "print(\"\\thaha\")\n",
    "print(\"\\\\thaha\")\n",
    "print(\"这是单引号'\")\n",
    "print('这是单引号\\'')\n",
    "#也可以通过r表示不转义\n",
    "print(r\"\\n表示换行\")\n",
    "print(r'\\t表示制表符')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello 同学们\n"
     ]
    }
   ],
   "source": [
    "#当字符串很长时，我们可以用续航符 \\\n",
    "#也就是转义符 \\newline来表示忽略换行\n",
    "print(\"hello \\\n",
    "同学们\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 字符串的操作符\n",
    "\n",
    "| 操作符 | 描述 |\n",
    "| --- | --- |\n",
    "| s1+s2 | 字符串s1和s2的连接 |\n",
    "| s*n 或 n*s | n是数字，表示字符串s重复n次 |\n",
    "| subs in s | 表示字符串subs是否在s中 |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "好好学习天天向上\n",
      "好好学习好好学习好好学习好好学习好好学习好好学习好好学习好好学习好好学习好好学习\n",
      "天天向上天天向上天天向上天天向上天天向上天天向上天天向上天天向上天天向上天天向上\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "s1 = '好好学习'\n",
    "s2 = '天天向上'\n",
    "print(s1 + s2)\n",
    "print(s1 * 10)\n",
    "print(10 * s2)\n",
    "print('好' in s1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 字符串处理函数\n",
    "下表是系统中一些关于字符串处理的内置方法\n",
    "\n",
    "| 函数 | 描述 |\n",
    "| --- | --- |\n",
    "| len(s) | 求字符串长度 |\n",
    "| str(n) | 返回任意类型数据n对应的字符串形式 |\n",
    "| chr(n) | 返回unicode编码x对应的字符 |\n",
    "| ord(c) | 返回字符c表示的unicode编码 |\n",
    "| hex(n) | 返回整数n对应十六进制数的小写形式字符串 |\n",
    "| oct(n) | 返回整数n对应的八进制数的小写形式字符串 |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6\n",
      "1.23\n",
      "True\n",
      "中\n",
      "20013\n",
      "0x4e2d\n",
      "0o47055\n"
     ]
    }
   ],
   "source": [
    "s = 'python'\n",
    "print(len(s))\n",
    "print(str(1.23))\n",
    "print(str(True))\n",
    "print(chr(20013))\n",
    "print(ord('中'))\n",
    "print(hex(20013))\n",
    "print(oct(20013))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 字符串方法\n",
    "\n",
    "| 方法 | 描述 |\n",
    "| --- | --- |\n",
    "| str.lower() | 返回str的小写形式，不改变str值 |\n",
    "| str.upper() | 返回str的大写形式，不改变str值 |\n",
    "| str.title() | 返回str的首字母大写模式，不改变str值 |\n",
    "| str.count(s) | 返回str中包含s的个数 |\n",
    "| str.startswith(s) | 返回str是否从s开始 |\n",
    "| str.center(width,fill) | 返回str填充fill字符到指定宽度width的字符串，str在新字符串中居中 |\n",
    "| str.strip(s) | 返回新字符串，去除了str的首尾包含在s中的字符 |\n",
    "| str.split(sep=None, maxsplit=-1) | 符串找sep分割，并返回分割后的包含多个字符串的列表 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i love python:I love Python\n",
      "I LOVE PYTHON:I love Python\n",
      "I Love Python\n",
      "2\n",
      "True\n",
      "True\n",
      "You love Python\n",
      "******************I love Python*******************\n",
      "I love Python\n",
      "love Pytho\n"
     ]
    }
   ],
   "source": [
    "s='I love Python'\n",
    "print(s.lower() + \":\" +s)\n",
    "print(s.upper() + \":\" +s)\n",
    "print(s.title())\n",
    "print(s.count('o'))\n",
    "print(s.startswith('I')) \n",
    "print(s.startswith('love',2))  #从位置2处开始\n",
    "print(s.replace('I','You'))\n",
    "news = s.center(50, '*')\n",
    "print(news)\n",
    "print(news.strip('*'))\n",
    "print(news.strip('*I n'))  #去掉首尾多个字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['I', 'love', 'Python']\n",
      "['I', 'love Python']\n",
      "['I love Py', 'on']\n",
      "['', '1', '2', '', '3', '']\n",
      "['', '']\n",
      "['1', '2', '3', '4']\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "#字符串分割\n",
    "#str.split(sep=None, maxsplit=-1)\n",
    "#字符串找sep分割，并返回分割后的包含多个字符串的列表\n",
    "#如果设置了maxsplit参数，则表示字符串最多按照sep分割多少次，一般不设置，默认为-1表示不限次数\n",
    "s='I love Python'\n",
    "print(s.split(' ')) #中间是空格\n",
    "print(s.split(' ', 1))\n",
    "#sep可以含有多个分隔符\n",
    "print(s.split('th')) \n",
    "#如果分隔符在头尾或者分隔符有多个连续一样的，则会分割出空字符串''\n",
    "print(',1,2,,3,'.split(','))\n",
    "print(','.split(','))\n",
    "#如果sep不设置，默认是None，则系统会按照所有空白字符串进行分割，比如空格，回车，制表符等,返回的列表中不会有空字符串''\n",
    "print(' 1 2\\t3\\n4 '.split())\n",
    "print(' \\t\\n'.split())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#####  字符串的查找\n",
    "\n",
    "str.find()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "3\n",
      "11\n"
     ]
    }
   ],
   "source": [
    "#\n",
    "s='I love Python'\n",
    "print(s.find('o'))\n",
    "print(s.find('o',3))\n",
    "print(s.find('o',4))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 字符串的格式化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我叫haha,我今年18岁了\n",
      "我今年18岁了，我叫haha\n",
      "我叫hehe,在软件1803班,我今年3岁了\n",
      "我有1024.62元钱\n",
      "反正就一个字形容我***帅***\n",
      "我的偶像是python老师\n",
      "我今年18岁了\n"
     ]
    }
   ],
   "source": [
    "#建议使用字符串的.format()方法来进行字符串个格式化操作，可读性和运行效率都比较高\n",
    "name='haha'\n",
    "age=18\n",
    "money=1024.625\n",
    "idol=['肖战','王一博','python老师']\n",
    "print('我叫{},我今年{}岁了'.format(name,age))\n",
    "print('我今年{1}岁了，我叫{0}'.format(name,age))\n",
    "print('我叫{name},在{ban}班,我今年{age}岁了'.format(name='hehe',age=3,ban='软件1803'))\n",
    "print('我有{:.2f}元钱'.format(money))\n",
    "print('反正就一个字形容我{:*^7}'.format(\"帅\"))\n",
    "print('我的偶像是{o[2]}'.format(o=idol))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我今年18岁了\n",
      "我今年18岁了\n"
     ]
    }
   ],
   "source": [
    "#不建议用以下格式化方法\n",
    "print('我今年'+str(age)+'岁了')\n",
    "print('我今年%d岁了' % (age))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### List 列表\n",
    "列表是python中数据类型之一，功能强大，类似于java里面的List。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "#创建列表\n",
    "empty = [] #可以初始化为空列表   \n",
    "student = ['haha','hehe','heihei'] #字符串列表\n",
    "score = [100,88,90]  #数值列表\n",
    "age = [18,'弱冠','而立'] #多种类型也可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['haha', 'hehe', 'heihei', '肖战']\n",
      "haha\n",
      "肖战\n",
      "['haha', 'hehe']\n",
      "['haha', 'heihei']\n",
      "[['haha', 'hehe', 'heihei', '肖战'], [100, 88, 90]]\n",
      "['haha', 'hehe', 'heihei', '肖战']\n",
      "[88, 90]\n",
      "4\n",
      "2\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "#添加元素到列表\n",
    "student.append('肖战')\n",
    "print(student)\n",
    "#访问列表中元素\n",
    "print(student[0])\n",
    "print(student[-1])\n",
    "print(student[:2])\n",
    "print(student[::2])  \n",
    "#其实列表的元素也可以是个列表\n",
    "course=[student,score]\n",
    "print(course)\n",
    "print(course[0])\n",
    "print(course[1][1:])\n",
    "#通过函数len可以得到列表长度\n",
    "print(len(student))\n",
    "print(len(course))\n",
    "#通过in关键字判断元素是否在列表中\n",
    "print('而立' in age)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 字符串的split方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "haha,hehe,heihei\n",
      "请输入你知道的病毒名称:冠状病毒 水痘 流感 感冒\n",
      "['冠状病毒', '水痘', '流感', '感冒']\n"
     ]
    }
   ],
   "source": [
    "#字符串和列表的转换\n",
    "print(','.join(student))\n",
    "virus = input(\"请输入你知道的病毒名称:\")\n",
    "print(virus.split())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 字符编码问题\n",
    "在计算机中，要保存任何文字，那么首先要对文件进行编码。世界上那么多国家和地区，有很多不同的文字，也就存在各种不同的编码方案。我们国家定义的方案有GB2312,GBK,GB18030等，美国有ASCII编码，全球有统一的unicode编码,python3中默认unicode编码。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "65\n",
      "21704\n",
      "B\n",
      "篙\n",
      "中文\n",
      "b'\\xe4\\xb8\\xad\\xe6\\x96\\x87'\n",
      "b'\\xd6\\xd0\\xce\\xc4'\n"
     ]
    }
   ],
   "source": [
    "print(ord('A'))\n",
    "print(ord('哈'))\n",
    "print(chr(66))\n",
    "print(chr(31705))\n",
    "print('\\u4e2d\\u6587')\n",
    "print('中文'.encode('utf-8'))\n",
    "print('中文'.encode('gbk'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 条件选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "同学，不要来上学，哥请你住宾馆\n"
     ]
    }
   ],
   "source": [
    "if#后面跟条件，以冒号结束，换行后一般缩进四个空格\n",
    "if '武汉' in personinfo:\n",
    "    print(\"同学，不要来上学，哥请你住宾馆\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "同学，我开车送你\n"
     ]
    }
   ],
   "source": [
    "# elif 和 else, \n",
    "if '南信院' in personinfo:\n",
    "    print('同学，我开车送你')\n",
    "elif '武汉' in personinfo:\n",
    "    print('同学，来一趟不容易啊，请你吃个饭')\n",
    "else:\n",
    "    print('同学你走错了')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入第一个数字:10\n",
      "请输入第二个数字:3\n",
      "最大值是:10\n"
     ]
    }
   ],
   "source": [
    "#条件表达式\n",
    "#Python中没有  ？：\n",
    "num1=int(input(\"请输入第一个数字:\"))\n",
    "num2=int(input(\"请输入第二个数字:\"))\n",
    "print(\"最大值是:{}\".format(num1 if num1>num2 else num2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "同学，请报口令:上海自来水来自海上\n",
      "请进\n"
     ]
    }
   ],
   "source": [
    "#经典回文\n",
    "word = input('同学，请报口令:')\n",
    "reversed_word = word[::-1]\n",
    "if word == reversed_word:\n",
    "    print(\"请进\")\n",
    "else:\n",
    "    print(\"施主请回罢\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1\n"
     ]
    }
   ],
   "source": [
    "#条件表达式中的特殊值\n",
    "if None:\n",
    "    print(\"None\")\n",
    "if 0:\n",
    "    print(\"0\")\n",
    "if(0.0):\n",
    "    print(\"0.0\")\n",
    "if '':\n",
    "    print('haha')\n",
    "if \"\":\n",
    "    print('hehe')\n",
    "if -1:\n",
    "    print('-1')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 循环"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 4 9 16 25 36 49 64 81 "
     ]
    }
   ],
   "source": [
    "#python中循环语句的一种常见写法\n",
    "#通过range函数表示遍历的范围\n",
    "#从1加10的平方\n",
    "for i in range(10):\n",
    "    print(i*i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 \n",
      "5 6 7 \n",
      "1 3 5 7 9 "
     ]
    }
   ],
   "source": [
    "#range(start,stop[,step])函数用于产生序列\n",
    "for i in range(3):\n",
    "    print(i,end=' ')\n",
    "print()\n",
    "for i in range(5,8):\n",
    "    print(i,end=' ')\n",
    "print()\n",
    "for i in range(1,10,2):\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#break和continue\n",
    "#循环中如果遇到break则跳出当前循环，遇到continue则继续下一轮循环\n",
    "#输出range(10,-10,-2)中的遇到0停止\n",
    "for i in range(10,-10,-2):\n",
    "    if not i:\n",
    "        break\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#输出range(10,10,-1)中不能被2或3整除的所有数字\n",
    "for i in range(10,-10,-1):\n",
    "    if i%2==0:\n",
    "        continue\n",
    "    if i%3==0:\n",
    "        continue\n",
    "    print(i,end=' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个整数，程序将输出1到该整数之间的所以质数：97\n",
      "所有的质数的是：\n",
      "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 "
     ]
    }
   ],
   "source": [
    "#任务：输入一个数字num，输出1到num之间所有质数\n",
    "#原理：#for后面也可以跟else，表示循环便利完了没有break就会进入else\n",
    "#如果循环没有break，则说明肯定是质数，就会执行else字句\n",
    "#所以我们在else字句中直接输出该质数\n",
    "num = int(input(\"请输入一个整数，程序将输出1到该整数之间的所以质数：\"))\n",
    "print('所有的质数的是：')\n",
    "for i in range(2, num + 1):\n",
    "    for j in range(2, i - 1):\n",
    "        if i % j == 0:\n",
    "            break\n",
    "    else:\n",
    "        print(i, end=\" \")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "反复输入一个自然数（>1），直到输入q停止，判断其是否是质数，如果是质数输出True，否则输出False，需要异常处理\n",
      "10\n",
      "False\n",
      "7\n",
      "True\n",
      "a\n",
      "输入异常\n",
      "---\n",
      "输入异常\n"
     ]
    }
   ],
   "source": [
    "#任务：反复输入一个自然数（>1），直到输入q停止，判断其是否是质数，如果是质数输出True，否则输出False，需要异常处理\n",
    "\n",
    "print('反复输入一个自然数（>1），直到输入q停止，判断其是否是质数，如果是质数输出True，否则输出False，需要异常处理')\n",
    "while True:\n",
    "    try:\n",
    "        snum = input(\"\")\n",
    "        if snum[0] in ['q','Q']:\n",
    "            break\n",
    "        intnum = int(snum)\n",
    "        if intnum <2:\n",
    "            print('输入的数值不大于1')\n",
    "            continue\n",
    "        for i in range(2, intnum):\n",
    "            if intnum % i == 0:\n",
    "                print(False)\n",
    "                break\n",
    "        else:\n",
    "            print(True)\n",
    "    except Exception:\n",
    "        print('输入异常')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#函数的基本结构如下,定义函数以def开头,后面紧跟函数名\n",
    "#括号里面是参数，只要写参数名即可，无需写类型。\n",
    "#return语句是返回值，可以省略，缺省返回None\n",
    "#经典函数-判断一年是否是闰年,能否更准确？\n",
    "def isleapyear(year):\n",
    "    return year%4==0 and (year%400==0 or year%100!=0)\n",
    "#判断2020是否闰年\n",
    "isleapyear(2020)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入年份:2100\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#任意输入一个年份，看是否闰年\n",
    "year = input(\"请输入年份:\")\n",
    "isleapyear(int(year))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#经典函数-判断是否质数\n",
    "def isprime(number):\n",
    "    for n in range(2,number):\n",
    "        if number%n==0:\n",
    "            return False\n",
    "    return True\n",
    "isprime(17)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个数字:5\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#任意输入一个数字，看是否为质数\n",
    "number = input(\"请输入一个数字:\")\n",
    "isprime(int(number))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 面向对象\n",
    "Python是具备面向对象特性的语言，我们之前写的数字，字符串，列表，函数等等都是对象。可以使用isinstance函数进行测试。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "True\n",
      "True\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "print(isinstance(8,object))\n",
    "print(isinstance(\"hahah\",object))\n",
    "print(isinstance(True,object))\n",
    "print(isinstance([\"哈哈\",\"呵呵\"],object))\n",
    "print(isinstance(isprime,object)) #之前定义过的"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 对象的id\n",
    "既然数字，字符串，列表，函数等等都是对象，那么在运行的时候会为每个用到的对象分配一个固定的id来指向这个对象。这个id往往就是内存地址。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "140729018127392\n",
      "140729018127392\n"
     ]
    }
   ],
   "source": [
    "a=8\n",
    "print(id(8))\n",
    "print(id(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 对象的占用空间\n",
    "我们可以通过对象的内置函数__sizeof__()来计算对象的占用空间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28\n",
      "28\n"
     ]
    }
   ],
   "source": [
    "print((8).__sizeof__())\n",
    "print(a.__sizeof__())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 对象的相等关系 ==和is\n",
    "==判断值是不是相等，is判断是不是同一个对象，也就是id是不是相等。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "a=1\n",
    "b=1.0\n",
    "c=[1,2]\n",
    "d=[1,2]\n",
    "print(a==b)\n",
    "print(a is b)\n",
    "print(c==d)\n",
    "print(c is d)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 模块的使用\n",
    "在python中我们经常会使用一些模块里面的功能，那么就要用import关键字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5.0\n",
      "1024.0\n",
      "10.0\n",
      "66\n"
     ]
    }
   ],
   "source": [
    "#引用一个模块\n",
    "import math\n",
    "print(math.sqrt(25))\n",
    "#引用模块里面的某些方法\n",
    "from math import pow,log2\n",
    "print(pow(2,10))\n",
    "print(log2(1024))\n",
    "#如果觉得应用的方法名太长，还可以改名\n",
    "#比如产生随机整数的方法randint可以重命名为rint\n",
    "#randint(0,100)产生0-100  [0,100]之间的整数\n",
    "from random import randint as 哈哈\n",
    "print(哈哈(0,100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "92"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "哈哈(0,100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 文件I/O\n",
    "Python中文件操作也很简单\n",
    "1. 通过open(filename,mode)函数就可以打开一个文件。mode主要有3中r,w,b，还有这三个的组合，比如rb,wb等。r表示只读，w表示写，b表示二进制方式。\n",
    "2. 通过read和write等方法读写文件\n",
    "3. 通过close方法关闭文件"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "文件的打开模式有\n",
    "\n",
    "| 打开模式 | 含义 |\n",
    "| ---- | ---- |\n",
    "| 'r' | 默认就是'r',只读模式，如果文件不存在，返回异常FileNotFoundError |\n",
    "| 'w' | 覆盖文件并写入，如果文件不存在则创建，如果存在则完全覆盖源文件 |\n",
    "| 'x' | 创建文件并写入，如果文件不存在则创建，如果存在则返回异常 FileExistsError |\n",
    "| 'a' | 文件后追加写入，如果文件不存在则创建，如果存在则在源文件最后追加内容 |\n",
    "| 'b' | 二进制文件模式 |\n",
    "| 't' | 文本文件模式，默认模式 |\n",
    "| '+' | 与r/w/x/a 组合使用，表示在原功能基础上增加同时读写功能 |\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "#把字符串64写入到文件haha.txt\n",
    "f=open('haha.txt','w')\n",
    "f.write(str(64))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#把数字64,65写入到文件\n",
    "bf=open('hehe.txt','wb')\n",
    "bf.write(bytes([64,65]))\n",
    "bf.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "@A\n"
     ]
    }
   ],
   "source": [
    "#文件的访问主要是打开，使用，关闭，如果在使用过程中出现异常，很容易出现文件没有关闭的情况，\n",
    "#我们可以在程序里面进行异常处理，我们后面会学，也可以使用with关键字来处理\n",
    "with open('hehe.txt','r') as haha:\n",
    "    s=haha.read()\n",
    "    print(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "#任务1， 随机产生100个[100-122]的数字，以字符方式写入到文件chars.txt，\n",
    "#这100个数字排序后以二进制方式写入到number.txt\n",
    "#观察这两个文件有哪些区别，写出来\n",
    "from random import randint\n",
    "numbers=[]\n",
    "with open('chars.txt','w') as f:\n",
    "    for i in range(0,100):\n",
    "        number=randint(100,122)\n",
    "        numbers.append(number)\n",
    "        f.write(str(number))\n",
    "sorted(numbers)\n",
    "with open('number.txt','wb') as fn:\n",
    "    fn.write(bytes(numbers))\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#任务2，编写程序，读取一个英文文档a.txt，然后转换成一个左右字符倒过来的文档ar.txt\n",
    "#比如文件a.txt中如果是'hello',那么ar.txt中就是'olleh'\n",
    "\n",
    "with open('pythoninfo.txt','r') as fpyinfo,open('pythoninfor.txt','w') as fpyinfor:\n",
    "    fpyinfor.write(fpyinfo.read()[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "#任务3，编写程序，实现中文文档b.txt中文字的倒序排列，输出到b.txt\n",
    "with open('pythoninfo-cn.txt','r',encoding='utf8') as fpyinfocn,open('pythoninfor-cn.txt','w',encoding='utf8') as fpyinforcn:\n",
    "    fpyinforcn.write(fpyinfocn.read()[::-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
